import java.util.*;

public class Graph {
	protected ArrayList vertices;
	
	Graph(){
		vertices = new ArrayList();
	}
	
	public void addVertex(Vertex v){
		vertices.add(v);
	}
	public void addEdge(Edge e){
		e.getHead().addEdge(e);
	}
	
	public int numberOfVertices(){
		return vertices.size();
	}
	public int numberOfEdges(){
		int result = 0;
		for(int i=0; i<vertices.size(); i++){
			result += ((Vertex)vertices.get(i)).edgeCount();
		}
		return result;
	}
	public Iterator outEdges(Vertex v){
		return v.outEdges();
	}
	public Iterator vertexIterator(){
		return vertices.iterator();
	}
	public String toString(){
		String result = "Graph";
		for(int i = 0; i<vertices.size(); i++){
			result += "\n" + vertices.get(i).toString();
		}
		return result;
	}
	
	private Vertex findVertex(String name){
		for(int i=0; i<vertices.size(); i++){
			if( ((Vertex)vertices.get(i)).getName() == name)
				return ((Vertex)vertices.get(i));
		}
		return null;
	}
}
